<template>
	<view>
		<view class="header">皮肤分析</view>
		<view class="list">
			<checkbox-group @change="bindSkin">
			  <label class="content" v-for="(item,index) in list" :key="item.name">
				<checkbox :value="item.name" :checked="item.checked"/>
				<view>{{item.name}}</view>
			  </label>
			</checkbox-group>
		</view>
		<view class="title">备注:</view>
		<textarea class="text_remark" auto-height maxlength="-1" v-model="remark"/>
		<button @click="addSkin" class="buttonClass">提交</button>
	</view>
</template>
<script>
import request from '@/util/request.js'
export default {
	data() {
		return {
			member_id:0,
			list:[],
			addSkinShow:false,
			skinNameStr:'',
			remark:''
		}
	},
	onLoad:function(e){
		uni.showLoading({
			title:'加载中.'
		})
		this.member_id = e.id
		this.getSkin()
	},
	methods: {
		getSkin:function(){
			var that = this
			request({
				url: 'manage/skin/name',
				method: 'get',
				success: (res) => {
					that.getSkinList(res.data.data)
				},
			})
		},
		addSkin:function(){
			if(!this.skinNameStr){
				uni.showToast({
					title: '请选择皮肤类型!!',
					icon: "none", 
					position:'bottom',
				});
				return;
			}
			var that = this
			var data = {
				skinNameStr:this.skinNameStr,
				oa_id:uni.getStorageSync('oa_id'),
				member_id:this.member_id,
				user_id:uni.getStorageSync('uid'),
				remark:this.remark
			}
			var pages = getCurrentPages();
			var currPage = pages[pages.length - 1]; //当前页面
			var prevPage = pages[pages.length - 2]; //上一个页面
			request({
				url: 'manage/skin/add',
				method: 'post',
				data:data,
				success: (res) => {
					if(res.data.code == 1){
						if(prevPage.route == 'manage/member/file'){
							prevPage.$vm.item.skinList = that.skinNameStr
						}
						uni.showToast({
							title:'提交成功',
							icon: 'none',
							duration: 2000,
							success() {
								setTimeout(function(){
									uni.navigateBack()
								}, 2000);
							}
						})
					}
				},
			})
		},
		bindSkin:function(e){
			var skinNameStr = e.detail.value
			this.skinNameStr = skinNameStr.join(',');
		},
		getSkinList:function(arr){
			var that = this
			var data = {
				member_id:this.member_id
			}
			request({
				url: 'manage/skin/list',
				method: 'get',
				data:data,
				success: (res) => {
					uni.hideLoading()
					if(res.data.data){
						that.skinNameStr =  res.data.data.skinNameStr
						that.remark =  res.data.data.remark
						that.checkArr(res.data.data.skinNameStr,arr)
					}else{
						that.list = arr;
					}
				},
			})
		},
		checkArr:function(str,arr){
			var data = str.split(',');
			for(var x in arr){
				if(data.indexOf(arr[x]['name']) > -1){
					arr[x]['checked'] = true
				}
			}
			this.list = arr;
		}
	},
}
</script>
<style>
@import url("../css/member/skin.css");
</style>